package com.ruoyi.project.lely.controller;

import com.ruoyi.project.lely.bean.dto.PageStudentDTO;
import com.ruoyi.project.lely.bean.entity.Student;
import com.ruoyi.project.lely.bean.vo.StudentVo;
import com.ruoyi.common.R;
import com.ruoyi.project.lely.service.ISysStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Desc: 学生测试
 * @Author LuoYong
 * @Date 2022/1/12 08:53
 */
@Api(tags = "Mini-学生")
@RestController
@RequestMapping("/mini/student")
public class StudentController {

    @Autowired
    private ISysStudentService studentService;

    @ApiOperation("查询单个")
    @GetMapping("/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok(studentService.getById(id));
    }

    @ApiOperation(value = "查询列表-全部")
    @PostMapping("/getAllList")
    public R<StudentVo> getAllList() {
        return studentService.getAllList();
    }

    @ApiOperation(value = "查询列表-分页", response = StudentVo.class)
    @PostMapping("/getPage")
    public R<StudentVo> getPage(@RequestBody PageStudentDTO dto) {
        return studentService.getPage(dto);
    }

    @ApiOperation("新增或修改")
    @PostMapping("/addOrUpdate")
    public R addOrUpdate(@Validated @RequestBody Student student) {
        return studentService.addOrUpdate(student);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable List<Long> ids) {
        boolean b = studentService.removeByIds(ids);
        return b ? R.ok("删除成功") : R.fail("删除失败");
    }


}
